package com.xxxy.exception;

import com.xxxy.commonResult.CommonResult;
import org.springframework.http.HttpStatus;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Objects;

/**
 * 全局参数、异常拦截
 */
//@RestControllerAdvice
//public class GlobalExceptionHandler {
//
//
//    //声明要捕获的异常
//    @ResponseStatus(HttpStatus.OK)
//    @ExceptionHandler(Exception.class)
//    @ResponseBody
//    public <T> CommonResult defaultExceptionHandler(Exception e) {
////        e.printStackTrace();
//        if(e instanceof MyException) {
//            return CommonResult.failed(ExceptionCodeEnum.FAILED,Objects.requireNonNull(e.getMessage()));
//        }
//        //参数不正确
//        if(e instanceof MissingServletRequestParameterException){
//            return CommonResult.failed(ExceptionCodeEnum.PRAM_NOT_MATCH, Objects.requireNonNull(e.getMessage()));
//        }
//        //未授权
//        if(e instanceof AuthorizationException){
//            return CommonResult.failed(ExceptionCodeEnum.FORBIDDEN);
//        }
//        //未知错误
//        return CommonResult.failed(ExceptionCodeEnum.ERROR,e.getMessage());
//    }
//}
